let vue = new Vue({
    el:'#login',
    delimiters:['${','}'], //用以区分django和vue语法  ${}为vue
    data:{
        // v-model
        username:'',
        password:'',

        //v-message
        error_username_msg:'用户名格式错误！',
        error_password_msg:'密码格式错误！',

        //v-show
        error_username:false,
        error_password:false,

        //qq 相关变量
        qq_url:'',

    },
    mounted(){
        //页面加载完成后自动调用执行当前函数
        this.get_qq_url();
    },
    methods:{
        get_qq_url:function (){
            axios.get('/qq/login',{
                responseType:'json'
            }).then(response=>{
                if (response.data.code=='200'){
                    this.qq_url = response.data.login_url;
                }
            }).catch(error=>{
               console.log(error.response);
            });
        },
        //校验用户名
        // check_uname:function (){
        //     //1.格式校验
        //     let reg1 = /^[A-Za-z][A-Za-z0-9_]{4,7}$/;
        //     let reg2 = /^1[3,5,7,8,9]\d{9}$/;
        //     if(!reg1.test(this.username) || !reg2.test(this.username)){
        //         this.error_username = true; //不匹配
        //     }else{
        //         this.error_username = false;
        //     }
        //
        // },
        //检验密码
        check_pwd:function (){
            let reg = /^[A-Za-z0-9_]{3,8}$/;
            if(!reg.test(this.password)){
                this.error_password = true;
            }else{
                this.error_password = false;
            }
        },
    }
});